//ST7796S PH035NA-01B

#include "ST7796S__PH035NA_01B.h"
#include "ssd2828.h"


void ST7796S__PH035NA_01B(void){


/*
	Enable command 2
	D[7:0] = C3h enable command 2 part I
	D[7:0] = 96h enable command 2 part II
	Disable command 2
	D[7:0] = 3Ch disable command 2 part I
	D[7:0] = 69h disable command 2 part II*/

	GP_COMMAD_PA(2);W_D(0xF0);  //Command Set Control
	W_D(0xC3);   
	GP_COMMAD_PA(2); W_D(0xF0);
	W_D(0x96);
	

	GP_COMMAD_PA(4);W_D(0xB6); // Display Function Control
	W_D(0x8A);
	W_D(0x07);
	//W_D(0x27);
	W_D(0x3b); //180829 

	/*GP_COMMAD_PA(5);W_D(0xB5); //Blanking Porch Control
	W_D(12);
	W_D(10);
	W_D(0x00);
	W_D(18);*/
	
	GP_COMMAD_PA(5);W_D(0xB5); //Blanking Porch Control
	W_D(VFPD);
	W_D(VBPD);
	W_D(0x00);
	W_D(HBPD);

	GP_COMMAD_PA(3);W_D(0xB1); //Frame Rate Control 
	W_D(0xA0);
	W_D(0x10);

	GP_COMMAD_PA(2);W_D(0x36); //Memory Data Access Control
	W_D(0x40); //adu 41

	GP_COMMAD_PA(2);W_D(0x38); // Idle Mode Off
	W_D(0x38);


	GP_COMMAD_PA(2);W_D(0x35);//Tearing Effect Line On
	W_D(0x00);

	GP_COMMAD_PA(2);W_D(0xB4); //Display Inversion Control
	W_D(0x01);

	GP_COMMAD_PA(2);W_D(0xB9); //Mode Selection
	W_D(0x02);
	W_D(0x00);

	GP_COMMAD_PA(2);W_D(0xC5); //VCOM Control
	W_D(0x20);

	GP_COMMAD_PA(3);W_D(0xC0); //Power Control 1
	W_D(0x80);
	W_D(0x77);

	GP_COMMAD_PA(2);W_D(0xC1); //Power Control 2
	W_D(0x1C);

	GP_COMMAD_PA(15);W_D(0xE0);
	W_D(0xF0);
	W_D(0x07);
	W_D(0x0E);
	W_D(0x0A);
	W_D(0x08);
	W_D(0x25);
	W_D(0x38);
	W_D(0x43);
	W_D(0x51);
	W_D(0x38);
	W_D(0x14);
	W_D(0x12);
	W_D(0x32);
	W_D(0x3F);


	GP_COMMAD_PA(15);W_D(0xE1);
	W_D(0xF0);
	W_D(0x08);
	W_D(0x0D);
	W_D(0x09);
	W_D(0x09);
	W_D(0x26);
	W_D(0x39);
	W_D(0x45);
	W_D(0x52);
	W_D(0x07);
	W_D(0x13);
	W_D(0x16);
	W_D(0x32);
	W_D(0x3F);


	GP_COMMAD_PA(2);W_D(0xF0); //Command Set Control
	W_D(0x3C);
	GP_COMMAD_PA(2);W_D(0xF0);
	W_D(0x69);

	GP_COMMAD_PA(2);W_D(0x3A); //Interface Pixel Format
	W_D(0x77); //adu0x75

	GP_COMMAD_PA(1);W_D(0x20); //Display Inversion Off    adu 0x21
	HAL_Delay(120); 
	GP_COMMAD_PA(1);W_D(0x11); //sleep out
	HAL_Delay(120); 

	GP_COMMAD_PA(1);W_D(0x29); //display on
	HAL_Delay(120); 
	GP_COMMAD_PA(5);W_D(0x2A); //Column Address Set
	W_D(0x00);
	W_D(0x00);
	W_D(0x01);
	W_D(0x3F);

	GP_COMMAD_PA(5);W_D(0x2B); //Row Address Set
	W_D(0x00);
	W_D(0x00);
	W_D(0x01);
	W_D(0xE0);

}